--帮会令牌NPC
--Author:逍遥子
--QQ 857904341
x805007_g_scriptId=805007
x805007_g_BuildingID15 = 6
x805007_g_eventList = {}
x805007_g_LingPaiItem = {10158001,10158002,10158003,10158004,10158005}
x805007_g_LingPaiGemTable = {
	[1] = {20800001,20800002,20800003,20800004,20800005,20800006}, 	--朱雀
	[2] = {20800007,20800008,20800009,20800010},					--青龙
	[3] = {20800011,20800012,20800013,20800014},					--玄武
	[4] = {20800015,20800016,20800017,20800018,20800019,20800020},	--白虎
}
--**********************************
--事件交互入口
--**********************************
function x805007_OnDefaultEvent( sceneId, selfId,targetId )
	
	local guildid 		= GetHumanGuildID(sceneId,selfId)
	local cityguildid = GetCityGuildID(sceneId, selfId, sceneId)
	local strText
	--雪舞临时取消帮派限制，因为我NPC移动到洛阳了【win7系统进入帮会老卡死。没办法】 2021-7-6 23:12:42
	-- if(guildid ~= cityguildid) then
		-- x805007_NotifyTip( sceneId, selfId,"#{BHZB_140521_38}")--H你不是本帮成员，请前往自己的帮会城市进行操作。
		-- return
	-- end
	
	BeginEvent(sceneId)
		strText = "#{BHZB_140521_144}"
		AddText(sceneId,strText)
		AddNumText(sceneId,x805007_g_scriptId,"#{BHZB_140521_2}",6,1)--兑换令牌
		AddNumText(sceneId,x805007_g_scriptId,"#{BHZB_140521_3}",6,2)--获取四象宝珠
		AddNumText(sceneId,x805007_g_scriptId,"#{BHZB_140521_8}",6,3)--令牌装备升阶
		AddNumText(sceneId,x805007_g_scriptId,"#{BHZB_140521_229}",6,4)--令牌星级提升
		AddNumText(sceneId,x805007_g_scriptId,"#{BHZB_140521_9}",6,5)--四象宝珠打造与升级
		AddNumText(sceneId,x805007_g_scriptId,"#{BHZB_140521_210}",6,6)--被动技能切换
		AddNumText(sceneId,x805007_g_scriptId,"#{BHZB_140521_10}",6,7)--扩展属性重铸
		AddNumText(sceneId,x805007_g_scriptId,"#{BHZB_140521_11}",11,8)--关于令牌
		AddNumText(sceneId,x805007_g_scriptId,"#{BHZB_140521_12}",11,9)--关于宝珠
		AddNumText(sceneId,x805007_g_scriptId,"#{BHZB_140521_13}",11,10)--关于天工坊
	EndEvent(sceneId)
	DispatchEventList(sceneId,selfId,targetId)
end

--**********************************
--事件列表选中一项
--**********************************
function x805007_OnEventRequest( sceneId, selfId, targetId, eventId )
	local nKey = GetNumText()
	if nKey == 1 then
		--兑换令牌
		BeginEvent(sceneId)	
			AddText(sceneId, "#{BHZB_140521_166}")
			AddRadioItemBonus( sceneId, x805007_g_LingPaiItem[1], 4 )
		EndEvent(sceneId)
		DispatchEventList(sceneId,selfId,targetId)
		DispatchMissionContinueInfo(sceneId,selfId,targetId, x805007_g_scriptId, 0)
		return
	end
	if nKey == 2 then
		BeginEvent(sceneId)
			AddText(sceneId,"#{BHZB_140521_31}")
			AddNumText(sceneId,x805007_g_scriptId,"#{BHZB_140521_4}",6,100)--红
			AddNumText(sceneId,x805007_g_scriptId,"#{BHZB_140521_5}",6,101)--绿
			AddNumText(sceneId,x805007_g_scriptId,"#{BHZB_140521_6}",6,102)--蓝
			AddNumText(sceneId,x805007_g_scriptId,"#{BHZB_140521_7}",6,103)--黄
		EndEvent(sceneId)
		DispatchEventList(sceneId,selfId,targetId)
		return
	end
	if nKey == 3 then --令牌升阶
		BeginUICommand(sceneId)
	        UICommand_AddInt( sceneId,targetId)
	        EndUICommand( sceneId )
	    DispatchUICommand( sceneId, selfId,  201405041)
		return
	end
	if nKey == 4 then --令牌升星
		BeginUICommand(sceneId)
	        UICommand_AddInt( sceneId,targetId)
	        EndUICommand( sceneId )
	    DispatchUICommand( sceneId, selfId,  201406285)
		return
	end
	if nKey == 5 then --宝珠相关操作
		BeginUICommand(sceneId)
	        UICommand_AddInt( sceneId,targetId)
	        EndUICommand( sceneId )
	    DispatchUICommand( sceneId, selfId,  201405043)
		return
	end
	if nKey == 6 then --令牌技能切换
		BeginUICommand(sceneId)
	        UICommand_AddInt( sceneId,targetId)
	        EndUICommand( sceneId )
	    DispatchUICommand( sceneId, selfId,  201405044)
		return
	end
	if nKey == 7 then --拓展属性
		BeginUICommand(sceneId)
	        UICommand_AddInt( sceneId,targetId)
	        EndUICommand( sceneId )
	    DispatchUICommand( sceneId, selfId,  201405042)
		return
	end
	if nKey == 8 then
		x805007_NotifyWind(sceneId,selfId,targetId,"#{BHZB_140521_14}")
		return
	end
	if nKey == 9 then
		x805007_NotifyWind(sceneId,selfId,targetId,"#{BHZB_140521_15}")
		return
	end
	if nKey == 10 then
		x805007_NotifyWind(sceneId,selfId,targetId,"#{BHZB_140521_16}")
		return
	end
	--下边是分支引用
	if nKey == 100 then --朱雀
		BeginEvent(sceneId)	
			AddText(sceneId, "#{BHZB_140521_32}")
			for i = 1, getn(x805007_g_LingPaiGemTable[1]) do
				AddRadioItemBonus( sceneId, x805007_g_LingPaiGemTable[1][i], 4 )
			end
		EndEvent(sceneId)
		DispatchEventList(sceneId,selfId,targetId)
		DispatchMissionContinueInfo(sceneId,selfId,targetId, x805007_g_scriptId, 0)
		return
	end
	if nKey == 101 then --青龙
		BeginEvent(sceneId)	
			AddText(sceneId, "#{BHZB_140521_33}")
			for i = 1, getn(x805007_g_LingPaiGemTable[2]) do
				AddRadioItemBonus( sceneId, x805007_g_LingPaiGemTable[2][i], 4 )
			end
		EndEvent(sceneId)
		DispatchEventList(sceneId,selfId,targetId)
		DispatchMissionContinueInfo(sceneId,selfId,targetId, x805007_g_scriptId, 0)
		return
	end
	if nKey == 102 then --玄武
		BeginEvent(sceneId)	
			AddText(sceneId, "#{BHZB_140521_34}")
			for i = 1, getn(x805007_g_LingPaiGemTable[3]) do
				AddRadioItemBonus( sceneId, x805007_g_LingPaiGemTable[3][i], 4 )
			end
		EndEvent(sceneId)
		DispatchEventList(sceneId,selfId,targetId)
		DispatchMissionContinueInfo(sceneId,selfId,targetId, x805007_g_scriptId, 0)
		return
	end
	if nKey == 103 then --白虎
		BeginEvent(sceneId)	
			AddText(sceneId, "#{BHZB_140521_35}")
			for i = 1, getn(x805007_g_LingPaiGemTable[4]) do
				AddRadioItemBonus( sceneId, x805007_g_LingPaiGemTable[4][i], 4 )
			end
		EndEvent(sceneId)
		DispatchEventList(sceneId,selfId,targetId)
		DispatchMissionContinueInfo(sceneId,selfId,targetId, x805007_g_scriptId, 0)
		return
	end
end
--**********************************
--接受此NPC的任务
--**********************************
function x805007_OnMissionAccept( sceneId, selfId, targetId, missionScriptId )
	for i, findId in x805007_g_eventList do
		if missionScriptId == findId then
			ret = CallScriptFunction( missionScriptId, "CheckAccept", sceneId, selfId )
			if ret > 0 then
				CallScriptFunction( missionScriptId, "OnAccept", sceneId, selfId )
			end
			return
		end
	end
	for i, findId in g_eventListTest do
		if missionScriptId == findId then
			ret = CallScriptFunction( missionScriptId, "CheckAccept", sceneId, selfId )
			if ret > 0 then
				CallScriptFunction( missionScriptId, "OnAccept", sceneId, selfId )
			end
			return
		end
	end
end

--**********************************
--拒绝此NPC的任务
--**********************************
function x805007_OnMissionRefuse( sceneId, selfId, targetId, missionScriptId )
	for i, findId in x805007_g_eventList do
		if missionScriptId == findId then
			x805007_UpdateEventList( sceneId, selfId, targetId )
			return
		end
	end
	for i, findId in g_eventListTest do
		if missionScriptId == findId then
			x805007_UpdateEventList( sceneId, selfId, targetId )
			return
		end
	end
end
--**********************************
--继续（已经接了任务）
--**********************************
function x805007_OnMissionContinue( sceneId, selfId, targetId, missionScriptId )
	for i, findId in x805007_g_eventList do
		if missionScriptId == findId then
			CallScriptFunction( missionScriptId, "OnContinue", sceneId, selfId, targetId )
			return
		end
	end
	for i, findId in g_eventListTest do
		if missionScriptId == findId then
			CallScriptFunction( missionScriptId, "OnContinue", sceneId, selfId, targetId )
			return
		end
	end
end
--**********************************
--提交已做完的任务
--**********************************
function x805007_OnMissionSubmit( sceneId, selfId, targetId, missionScriptId, selectRadioId )
	for i, findId in x805007_g_eventList do
		if missionScriptId == findId then
			CallScriptFunction( missionScriptId, "OnSubmit", sceneId, selfId, targetId, selectRadioId )
			return
		end
	end
	local guildid 	= GetHumanGuildID(sceneId,selfId)
	local cityguildid = GetCityGuildID(sceneId, selfId, sceneId)
	--判断是不是帮会成员
	-- if guildid ~= cityguildid then
		-- x805007_NotifyWind(sceneId,selfId,targetId,"#{BHZB_140521_17}")
		-- x805007_NotifyTip( sceneId, selfId, "#{BHZB_140521_18}" )
		-- return
	-- end
	--判断加入的时间
	local nFactionJoinTime = GetFactionJoinTime( sceneId, selfId );
	local nTimeCur = LuaFnGetCurrentTime()
	local nTimeDelta = nTimeCur - nFactionJoinTime;
	if nTimeDelta < 10 then --3天的限制
		x805007_NotifyWind(sceneId,selfId,targetId,"#{BHZB_140521_19}")
		x805007_NotifyTip( sceneId, selfId, "#{BHZB_140521_20}" )
		return
	end
	--看看等级是不是够
	if GetLevel(sceneId,selfId) < 80 then
		x805007_NotifyWind(sceneId,selfId,targetId,"#{BHZB_140521_21}")
		x805007_NotifyTip( sceneId, selfId, "#{BHZB_140521_22}" )
		return
	end
	--检查帮会状态
	if CityGetMaintainStatus(sceneId, selfId, sceneId) == 1  then
		x805007_NotifyWind(sceneId,selfId,targetId,"#{BHZB_140521_23}")
		x805007_NotifyTip( sceneId, selfId, "#{BHZB_140521_24}" )
		return
	end
	if selectRadioId == x805007_g_LingPaiItem[1] then
		--取到帮贡
		local nContribPoint = CityGetAttr(sceneId, selfId, GUILD_CONTRIB_POINT);
		if nContribPoint < 100 then
			x805007_NotifyWind(sceneId,selfId,targetId,"#{BHZB_140521_25}")
			x805007_NotifyTip( sceneId, selfId, "#{BHZB_140521_26}" )
			return
		end
		--检查装备背包空间
		if LuaFnGetPropertyBagSpace( sceneId, selfId) < 1  then
			x805007_NotifyWind(sceneId,selfId,targetId,"#{BHZB_140521_29}")
			x805007_NotifyTip( sceneId, selfId, "#{BHZB_140521_30}" )
			return
		end
		CityChangeAttr(sceneId, selfId, GUILD_CONTRIB_POINT, -100)--扣除100帮贡
		TryRecieveItem(sceneId,selfId, x805007_g_LingPaiItem[1] ,1)--帮贡给了
		x805007_NotifyWind(sceneId,selfId,targetId,"#{BHZB_140521_27}")
		x805007_NotifyTip( sceneId, selfId, "#{BHZB_140521_28}" )
		LuaFnSendSpecificImpactToUnit(sceneId, selfId, selfId, selfId, 149, 0)
		return
	end
	--兑换宝珠
	if selectRadioId >= 20800001 and selectRadioId <= 20800020 then
		--取到帮贡
		local nContribPoint = CityGetAttr(sceneId, selfId, GUILD_CONTRIB_POINT);
		if nContribPoint < 50 then
			x805007_NotifyWind(sceneId,selfId,targetId,"#{BHZB_140521_25}")
			x805007_NotifyTip( sceneId, selfId, "#{BHZB_140521_26}" )
			return
		end
		--检查装备背包空间
		if LuaFnGetPropertyBagSpace( sceneId, selfId) < 1  then
			x805007_NotifyWind(sceneId,selfId,targetId,"#{BHZB_140521_29}")
			x805007_NotifyTip( sceneId, selfId, "#{BHZB_140521_30}" )
			return
		end
		CityChangeAttr(sceneId, selfId, GUILD_CONTRIB_POINT, -50)--扣除100帮贡
		TryRecieveItem(sceneId,selfId, selectRadioId ,1)--帮贡给了
		x805007_NotifyTip( sceneId, selfId, "#{BHZB_140521_37}" )
		LuaFnSendSpecificImpactToUnit(sceneId, selfId, selfId, selfId, 149, 0)
		return
	end
end
--**********************************
-- 兑换类通用检测
--**********************************
function x805007_CheckConditionOnExchange(sceneId,selfId,targetId)
	
end
--**********************************
-- 提示窗口
--**********************************
function x805007_NotifyWind(sceneId,selfId,targetId,Msg)
	BeginEvent( sceneId )
	AddText( sceneId, Msg )
	EndEvent( sceneId )
	DispatchEventList( sceneId, selfId, targetId )
end
--**********************************
-- 屏幕中间提示
--**********************************
function x805007_NotifyTip( sceneId, selfId, Msg )
	BeginEvent( sceneId )
	AddText( sceneId, Msg )
	EndEvent( sceneId )
	DispatchMissionTips( sceneId, selfId )
end